﻿@inject IHttpService _httpService
@inject IPopupService PopupService
@inject IEventService _eventService

<MDCard>
    <DataTableCard TModel="GameScoreTableModel" Headers="_headers" ApiUrl="@(_baseUrl)" ShowAddButton="false" Title="@($"{_name}列表")" @ref="dataTableCard">
        <ItemColContent>
            @if (context.Header.Value == "actions")
            {
                <MIcon Color="info"
                       Class="mr-2"
                       OnClick="()=>LookItem(context.Item)">@IconType.Look.ToIconString()</MIcon>
            }
            else
            {
                @context.Value
            }
        </ItemColContent>
    </DataTableCard>

</MDCard>



@code {
    private bool _editDialog;
    private long _editedItemId;
    private bool _detailDialog;

    private string _baseUrl = "api/tables/ListGameScores";
    private string _name = "评分";

    private List<DataTableHeader<GameScoreTableModel>> _headers = new List<DataTableHeader<GameScoreTableModel>>
    {
        new ()
          {
            Text= "Id",
            Align= DataTableHeaderAlign.Start,
            Value= nameof(GameScoreTableModel.GameId)
          },
          new (){ Text= "游戏名", Value= nameof(GameScoreTableModel.GameName)},
          new (){ Text= "配音", Value= nameof(GameScoreTableModel.AllCVSocre)},
          new (){ Text= "程序", Value= nameof(GameScoreTableModel.AllSystemSocre)},
          new (){ Text= "演出", Value= nameof(GameScoreTableModel.AllShowSocre)},
          new (){ Text= "美术", Value= nameof(GameScoreTableModel.AllPaintSocre)},
          new (){ Text= "剧本", Value= nameof(GameScoreTableModel.AllScriptSocre)},
          new (){ Text= "音乐", Value= nameof(GameScoreTableModel.AllMusicSocre)},
          new (){ Text= "总分（所有）", Value= nameof(GameScoreTableModel.AllTotalSocre)},
          new (){ Text= "配音", Value= nameof(GameScoreTableModel.FilterCVSocre)},
          new (){ Text= "程序", Value= nameof(GameScoreTableModel.FilterSystemSocre)},
          new (){ Text= "演出", Value= nameof(GameScoreTableModel.FilterShowSocre)},
          new (){ Text= "美术", Value= nameof(GameScoreTableModel.FilterPaintSocre)},
          new (){ Text= "剧本", Value= nameof(GameScoreTableModel.FilterScriptSocre)},
          new (){ Text= "音乐", Value= nameof(GameScoreTableModel.FilterMusicSocre)},
          new (){ Text= "总分（过滤后）", Value= nameof(GameScoreTableModel.FilterTotalSocre)},
          new (){ Text= "操作", Value= "actions",Sortable=false }
    };

    DataTableCard<GameScoreTableModel> dataTableCard;

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    public async Task LookItem(GameScoreTableModel model)
    {
        await _eventService.OpenNewPage("https://www.cngal.org/entries/index/" + model.GameId);
    }
}
